package czk.concrent.protectpause;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author:ChenZhangKun
 * @Date: 2020/5/25 23:04
 */
public class DownLoader {
    public List<String> download() throws IOException, InterruptedException {
        HttpURLConnection connection=(HttpURLConnection) new URL("http://www.baidu.com").openConnection();
        List<String> list=new ArrayList<>();
        try (BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8))){
                String line;
                while ((line=bufferedReader.readLine())!=null){
                    list.add(line);
                }
        }
        System.out.println("下载完毕");
        Thread.sleep(5*1000);
        return list;
    }
}
